import { getDeptPosTreeIcon } from '@/utils';

export const filterTree = (tree) => {
  if (!tree || !Array.isArray(tree)) {
    return [];
  }

  return tree
    .filter((node) => node.textType === '0')
    .map((node) => ({
      ...node,
      children: filterTree(node.children),
    }));
};

/** 处理搜索组织机构部门 */
export const handleDutySearchList = (selectData: any[], name: any, value: any) => {
  let loopList: any = (dataList: any[]) => {
    return dataList?.map((item: any) => {
      return {
        ...item,
        name: (
          <span>
            {getDeptPosTreeIcon(String(item?.textType))}
            {item?.[`${name}`]}
          </span>
        ),
        // name: item?.[`${name}`],
        treeName: item?.[name],
        value: item?.[`${value}`],
        children: item?.children && item?.children?.length > 0 ? loopList(item?.children) : null,
        disabled: item?.textType == 1 ? true : false,
      };
    });
  };
  let newMapList = loopList(selectData);
  return newMapList;
};
